Ext.define('App.management.pm.view.PmIterationReportFrame', {
    extend: 'App.management.pm.view.PmBaseFrame',
    alias: ['widget.PmIterationReportFrame'],
    requires: ['App.report.iteration.view.IterationReportList'],
    listeners:
        {
            afterrender: function () {
                var me = this;
                me.loadReport();
            }
        },
    loadReport: function () {
        var me = this;
        if (Ext.isEmpty(app.project)) {
            return;
        }
        me.mask('加载报表...');
        Ext.Ajax.request({
            url: 'report_configuration/query_iteration_report_configuration',
            params: {projectId: app.project.id},
            success: function (resp) {
                var rcs = resp.result.data;
                if (Ext.isArray(rcs)) {
                    Ext.Array.each(rcs, function (item) {
                        var report = Ext.create('App.report.iteration.view.IterationReportList', {
                            title: item.name,
                            projectId: app.project.id,
                            reportConfiguration: item
                        })
                        if (item.name == "关键指标") {
                            var tbs = report.getDockedItems('toolbar[dock="top"]');
                            if (!Ext.isEmpty(tbs) && tbs.length > 0) {
                                tbs[0].add({
                                    text: '清理关键指标',
                                    handler: function () {
                                        me.clearKpis(report);
                                    }
                                });
                            }
                        }
                        me.addTabitem(report)

                    })
                }
                me.setActiveTab(0)
                me.unmask();
            },
            failure: function () {
                me.unmask();
            }
        });
    },
    tabitems: [],
    clearKpis: function (view) {
        view.mask('加载...')
        Ext.Ajax.request({
            url: 'target_configuration/clear_pivotal_kpiss_by_project',
            params: {projectId: app.project.id},
            success: function (resp) {
                if (resp.result.success == true) {
                    view.reload();
                }
                view.unmask();
            },
            failure: function () {
                view.unmask();
            }
        });
    }
})